package com.qding.park.common.utils.rchl;




import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


public class RchlDateUtil {

	/**
	 * @param args
	 */
	
	public static int getCurrentTimeYear(){
		Calendar  ca = Calendar.getInstance();
		return ca.get(Calendar.YEAR);
	}
	
	public static int getCurrentTimeMonth(){
		Calendar  ca = Calendar.getInstance();
		return ca.get(Calendar.MONTH)+1;
	}
	
	public static int getCurrentTimeDay(){
		Calendar  ca = Calendar.getInstance();
		return ca.get(Calendar.DAY_OF_MONTH);
	}
	
	
	public static String getDateyyyymmdd(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMdd");
		return (sf.format(date)).toString();
	}
	
	public static String getDatehhmmss(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("HHmmss");
		return (sf.format(date)).toString();
	}
	
	public static String getDateyyyymm(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMM");
		return (sf.format(date)).toString();
	}
	public static String getDateyyyy_mm_dd_HH_mm_ss(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return (sf.format(date)).toString();
	}
	public static String getDateyyyy_mm_dd_HH_mm_ss_SSS(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
		return (sf.format(date)).toString();
	}
	public static Date getDateyyyy_mm_dd_HH_mm_ss_SSS(String dateStr){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
		
		Date returnDate = null;
		try {
			returnDate = sf.parse(dateStr);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnDate;
	}
	
	public static Date getDateyyyymmdd(String dateStr){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMdd");
		
		Date returnDate = null;
		try {
			returnDate = sf.parse(dateStr);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnDate;
	}
	
	
	public static Date getDateyyyymmddHHmmss(String dateStr){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMddHHmmss");
		Date returnDate = null;
		try {
			returnDate = sf.parse(dateStr);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnDate;
	}
	
	public static Date getDateyyyy_mm_dd_HH_mm_ss(String dateStr){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date returnDate = null;
		try {
			returnDate = sf.parse(dateStr);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return returnDate;
	}
	public static String getDateyyyymmddHHmmssSSS(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
		return (sf.format(date)).toString();
	}
	public static String getDateyyyymmddHHmmss(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMddHHmmss");
		return (sf.format(date)).toString();
	}	
	
	public static String getDateyyyymmddHHmm(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMddHHmmss");
		return (sf.format(date)).toString();
	}
	
	public static String getDateHHmmssSSS(Date date){
		SimpleDateFormat  sf = new SimpleDateFormat("HHmmssSSS");
		return (sf.format(date)).toString();
	}
	
	public static String getDateyyyy_MM_dd(String dateStr) {
		if(RchlStringUtil.isEmpty(dateStr)) {
			return "";
		}
		
		SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMdd");
		Date date = null;
		try {
			date = sf.parse(dateStr);
		} catch (ParseException e) {
			return "";
		}
		
		sf = new SimpleDateFormat("yyyy-MM-dd");
		return sf.format(date);
	}
	
	public static String getMonthAbbr(int index) {
		String[] monthArray = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","DEC","UND"};
		if(index >= 0 && index < monthArray.length) {
			return monthArray[index];
		}
		return "";
	}
	
	public static String calculateDate(String dateStr, int day) {
		try {
			SimpleDateFormat  sf = new SimpleDateFormat("yyyyMMdd");
			Date date = sf.parse(dateStr); // ��ǰ����
			
			Calendar cal=Calendar.getInstance();
			cal.setTime(date);
			cal.add(Calendar.DAY_OF_MONTH,day);	// ����
			
			Date date2 = cal.getTime();
			String outDateStr = sf.format(date2);
			return outDateStr;
		} catch (Exception e) {
			e.printStackTrace();
			return "";
		}
	}
	
	public static void main(String[] args) {
		
		System.out.println(getDateyyyymmddHHmmss(new Date()));
	}
}
